package com.xjtu.chapter09;

import java.util.LinkedList;

/**
 * @author yjq
 * @version 1.0
 * @date 2021/9/2 21:21
 */
public class GenericTest3<E> {
    //创建一个LinkedList,具体放置元素用E代替
    private LinkedList<E> list = new LinkedList<E>();

    public void push(E o) {
        list.addFirst(o);//压栈
    }

    public E top() {
        return list.getFirst();//查询栈顶元素
    }

    public E pop() {
        return list.removeFirst();//出栈
    }

    @Override
    public String toString() {
        return list.toString();
    }

    public static void main(String[] args) {
        GenericTest3<String> sl = new GenericTest3<>();
        for (int i = 0; i < 5; i++) {
            sl.push(String.valueOf(i));
        }
        System.out.println("s1 = " + sl);
    }
}
